package com.easyjava.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: 小闹心
 * @Description: 配置文件工具类
 * @DateTime: 2024/11/16 9:28
 **/
public class PropertiesUtils {
    private static Properties prop = new Properties();
    private static Map<String,String> PROPER_MAP = new ConcurrentHashMap<>();

    static {
        InputStream is = null;
        try{
            is = PropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties");
//            prop.load(is);
            prop.load(new InputStreamReader(is, StandardCharsets.UTF_8));
            Iterator<Object> iterator = prop.keySet().iterator();
            while(iterator.hasNext()){
                String key = (String) iterator.next();
                PROPER_MAP.put(key,prop.getProperty(key));
            }
        }catch (Exception e){

        }finally {
            try {
                if(is != null){
                    is.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static String getString(String key){
        return PROPER_MAP.get(key);
    }
}
